jsx3.Class.defineClass(
	"tibco.admin.monitormanage.general.NavigationHandler",                   // the full name of the class to create
    jsx3.lang.Object, //  extends
	null,  // does not implement an interface
	function(handler) {
	
		handler.mainPageNavigationTopic = "com.tibco.admin.monitormanage.general.NavigationHandler.navigation";
		handler.mainPageDisplayTopic = "com.tibco.admin.monitormanage.general.NavigationHandler.display"; 
		
		handler.prototype.cachedScreenIdList;
		handler.prototype.cachedScreenInfoList;
		handler.prototype.displayedScreenIds;

	/**
         *  Not for public consumption
         */		
		handler.prototype.init = function() {
			this.jsxsuper();
			tibco.admin.monitormanage.general.PageBusUtils.subscribe(handler.mainPageNavigationTopic, this.handleMainPageNavigation, this);
			this.cachedScreenIdList = new jsx3.util.List();
			this.cachedScreenInfoList = new jsx3.util.List();
			this.displayedScreenIds = new jsx3.util.List();
		}

	/**
         *  Not for public consumption
         */		
		handler.prototype.registerMainPageScreen = function(tab, screenId, callbackTarget) {
			if(!tibco.admin.monitormanage || !tibco.admin.monitormanage.framework || !tibco.admin.monitormanage.framework.mainPage || !tibco.admin.monitormanage.framework.mainPage.MainPageScreenInfo)
            { tibco.admin.Main.loadClass("tibco/admin/monitormanage/framework/mainPage/MainPageScreenInfo.js", this.getNamespace()); }			
            var screenInfo = new tibco.admin.monitormanage.framework.mainPage.MainPageScreenInfo(tab, callbackTarget);
            this.cachedScreenIdList.add(screenId);
            this.cachedScreenInfoList.add(screenInfo);
		}
		
		handler.prototype.getNamespace = function() {
        	return "tibco.admin";
        }
        
	/**
         *  Publishes a navigational message triggering the UI to display the screen identified by the screenId
         *  @param screenIdVal the id of the screen to display
         *  @param parameterArrayVal the parameter object which will be passed into the "displayScreen" method of main screen being displayed
         *  @param tabClickedVal a boolean indicating whether the to programatically select the navigation tab
         */
        handler.publishMainPageNavigationMessage = function(screenIdVal, parameterArrayVal, tabClickedVal) {
    		var message = { parameterArray:parameterArrayVal, screenId:screenIdVal, tabClicked:tabClickedVal};
        	tibco.admin.monitormanage.general.PageBusUtils.publish(handler.mainPageNavigationTopic, message);
        }

	/**
         *  Not for public consumption
         */
		handler.prototype.handleMainPageNavigation = function(subject, message, navHandler) {
			var tabClicked = message.tabClicked;
			var screenId = message.screenId;
			var parameterArray = message.parameterArray;
			if(navHandler.cachedScreenIdList.contains(screenId))
			{
				var idx = navHandler.cachedScreenIdList.indexOf(screenId);
				var screenInfo = navHandler.cachedScreenInfoList.get(idx);
				var callbackObj = screenInfo.getCallbackTarget();
	
				if(!callbackObj.isComponentLoaded())
				{ 
					callbackObj.loadComponent(callbackObj.getParentObj());
					callbackObj.setComponentWasLoaded(true);
				}
				
				// display the appropriate tab
				if(!tabClicked)
				{ screenInfo.getTab().select(); }
					
				// build the screen if necessary 
				if(!navHandler.displayedScreenIds.contains(screenId))
				{
					callbackObj.buildScreen(screenId, parameterArray);
					navHandler.displayedScreenIds.add(screenId);
				}
				
				// now make the call to display the screen
				callbackObj.displayScreen(screenId, parameterArray);
			}
		}
	}
);